package com.atkxp.dao.impl;

import com.atkxp.dao.UserDao;
import com.atkxp.domain.User;
import com.atkxp.utils.JdbcUtils;

import java.sql.Connection;

/**
 * @author user
 * @declaration
 * @create 2022/9/17-9:54
 */
public class UserDaoImpl extends BaseDao<User> implements UserDao {
    Connection con = JdbcUtils.getConnection();
    @Override
    public User queryWithUsername(String username) {
        String sql = "select id, username, password, email from t_user where username = ?";
        return getInstance(sql, username);
    }

    @Override
    public User queryWithUsernameAndPassword(String username, String password) {
        String sql = "select id, username, password, email from t_user where username = ? && password = ?";
        return  getInstance(sql, username, password);
    }

    @Override
    public int savaUser(User user) {
        String sql = "insert into t_user(username, `password`, email) VALUES(?, ?, ?)";
        return update(sql, user.getUsername(), user.getPassword(), user.getEmail());
    }
}
